<template>

	<view>
		<my-search :bgColor=" '#c00000' "  radius="18" @myclick="goToSearch"></my-search>

		<view class="scrool_view_container">
			<!-- 左侧滑动区域-->
			<scroll-view scroll-y="true" class="left_scrool_view" :style="{height:vh+ 'px'}">
				<view v-for="(item,index) in cateList" :key="index"
					:class="[ 'left_scroll_view_item',index===active?'active':' ']" @click="activeChange(index)">
					{{item.cat_name}}
				</view>
			</scroll-view>

			<!-- 右侧滑动的区域-->
			<scroll-view scroll-y="true" :scroll-top="scrollTop" class="right_scrool_view" :style="{height:vh + 'px'}">
				<view class="right_scroll_view_item" v-for="(item2,index) in cateLevel2">

					<!-- 二级分类的标题 -->
					<view class="cate_lv2_title">
						/{{item2.cat_name}}/
					</view>
					<!-- 当前二级分类下的三级分类列表 -->
					<view class="cate_lv3_list">
						<!-- 三级分类的Item项 -->
						<view class="cate_lv3_item" v-for="(item3,index3) in item2.children"
							@click="goGoodsList(item3)">
							<!-- 三级分类的图片 -->
							<image :src="item3.cat_icon" mode=""></image>
							<!-- 三级分类的文本 -->
							<view>{{item3.cat_name}}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		
	</view>
	
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		
		mixins:[badgeMix],
		data() {
			return {
				//窗口的可用高度=屏幕高度-navigationBar高度-tabBar高度
				vh: 0,
				cateList: [],
				// 当前选中项的索引，默认让第一项被选中
				active: 0,
				//二级分类的列表
				cateLevel2: [],
				//滚动到顶部
				scrollTop: 0,
			};
		},
		methods: {
			async getCateList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/categories')
				console.log("data", res)
				if (res.meta.status !== 200)
					return uni.$showMsg()

				this.cateList = res.message;
				this.cateLevel2 = this.cateList[0].children;
			},
			activeChange(index) {
				console.log("当前点击是", )
				this.active = index;
				this.cateLevel2 = this.cateList[index].children;
				this.scrollTop = this.scrollTop === 0 ? 1 : 0;
			},
			goGoodsList(item) {
				uni.navigateTo({
					url: '/subpkg/goods_list/goods_list?cid=' + item.cat_id
				})
			},goToSearch(){
				 uni.navigateTo({
				 	url:"/subpkg/search/search"
				 })
			}
		},
		onLoad() {
			// 获取当前系统的信息
			const sysInfo = uni.getSystemInfoSync();
			// console.log("设备信息", sysInfo)
			this.vh = sysInfo.windowHeight-50;

			this.getCateList();
		}
	}
</script>

<style lang="scss">
	.scrool_view_container {
		display: flex;

		.left_scrool_view {
			width: 200rpx;
			// height: 560rpx;
			background-color: #F7F7F7;
			line-height: 60px;
			text-align: center;
			font-size: 12px;

			.left_scroll_view_item {

				&.active {
					background-color: #FFFFFF;
					position: relative;
					// color:  #C00000;
					// border-left: 5rpx solid  #C00000;
					// padding: 3px 10px;

					&::before {

						content: ' ';
						width: 3px;
						height: 30px;
						background-color: #C00000;

						position: absolute;
						left: 1px;
						top: 50%;
						transform: translateY(-50%);
					}
				}
			}
		}

		.cate_lv2_title {
			font-size: 11px;
			font-weight: bold;
			text-align: center;
			padding: 15px 0;
		}

		.cate_lv3_list {
			display: flex;
			flex-wrap: wrap;

			.cate_lv3_item {
				width: 33.33%;
				text-align: center;

				// display: flex;
				// justify-content: center;
				// align-items: center;
				// flex-direction: column;
				margin-bottom: 10px;

				image {
					width: 60px;
					height: 60px;
				}

				view {
					font-size: 11px;
				}
			}

		}
	}
</style>
